package com.kehongborui.empmanagesys.service;

import com.kehongborui.empmanagesys.dao.EmpDao;
import com.kehongborui.empmanagesys.entity.Emp;
import com.kehongborui.empmanagesys.model.QueryCondition;
import com.kehongborui.empmanagesys.util.CommonUtil;

import java.util.List;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-07-20
 */
public class QueryService {
    private EmpDao empDao = new EmpDao();
    public List<Emp> query(String name, String age, String salMin, String salMax, String gender) {
        // 1.封装查询对象
        // 2. 根据条件查询：写dao 中的查询逻辑
        // 3. 将查询结果返回
        QueryCondition condition = new QueryCondition();

        if (!CommonUtil.isEmpty(age)) {
            condition.setAge(Integer.parseInt(age));
        }

        if (!CommonUtil.isEmpty(name)) {
            condition.setName(name);
        }

        if (!CommonUtil.isEmpty(salMax)) {
            condition.setSalMax(Integer.parseInt(salMax));
        }

        if (!CommonUtil.isEmpty(salMin)) {
            condition.setSalMin(Integer.parseInt(salMin));
        }

        if (!CommonUtil.isEmpty(gender)) {
            condition.setGender(Integer.parseInt(gender));
        }

        return empDao.query(condition);
    }
}
